package dao;

import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import dto.AddressDTO;
import dto.FileListDTO;
import dto.MemberDTO;
import dto.PrivacyDTO;
import dto.PropertyDTO;
import dto.RefundDTO;
import dto.RoomDTO;

public class RoomDAO {
	private SqlMapClientTemplate sqlMap;
	public RoomDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	public void insertRoom(RoomDTO rdto)  throws SQLException{
		sqlMap.insert("insertRoom", rdto);
	}
	public int selectRoomNo() throws SQLException{
		return (Integer)sqlMap.queryForObject("roomNumberGen");
	}
	public int selectFileNo() throws SQLException{
		return (Integer)sqlMap.queryForObject("fileNumberGen");
	}
	public void insertFile(FileListDTO fdto)  throws SQLException{
		sqlMap.insert("insertFile", fdto);
	}
	public ArrayList<AddressDTO> searchAddress(String dong) {
		return (ArrayList<AddressDTO>) sqlMap.queryForList("searchAddress",dong);
	}
	public PropertyDTO selectPropertyId(String propertyId) throws SQLException{
		return (PropertyDTO)sqlMap.queryForObject("selectPropertyId", propertyId);
	}
	public PrivacyDTO selectPrivacyId(String privacyId) throws SQLException{
		return (PrivacyDTO)sqlMap.queryForObject("selectPrivacyId", privacyId);
	}
	public RefundDTO selectRefundId(String refundId) throws SQLException{
		return (RefundDTO)sqlMap.queryForObject("selectRefundId", refundId);
	}
	public AddressDTO selectAddress(String addressId) throws SQLException{
		return (AddressDTO)sqlMap.queryForObject("searchBySeq", addressId);
	}
	public void removeRoom(int roomNo) throws SQLException{
		sqlMap.delete("removeRoom", roomNo);
	}
	public ArrayList<FileListDTO> selectFileListByRoomNo(int roomNo) throws SQLException{
		return (ArrayList<FileListDTO>)sqlMap.queryForList("selectFileListByRoomNo", roomNo);
	}
	public RoomDTO selectByRoomNo(int roomNo) throws SQLException{
		return (RoomDTO)sqlMap.queryForObject("selectByRoomNo", roomNo);
	}
	public ArrayList<RoomDTO> selectByMemberId(String memberId) throws SQLException{
		return (ArrayList<RoomDTO>)sqlMap.queryForList("selectByMemberId", memberId);
	}
	
	public ArrayList<RoomDTO> selectMyRoomListByMemberId(String memberId) throws SQLException{
		return (ArrayList<RoomDTO>)sqlMap.queryForList("selectMyRoomListByMemberId", memberId);
	}
	public FileListDTO selectRoomFileByRoomNo(int roomNo) throws SQLException{
		return (FileListDTO)sqlMap.queryForObject("selectMainFile", roomNo);
	}
	public RoomDTO selectRoomDetailByRoomNo(int roomNo) throws SQLException{
		return (RoomDTO)sqlMap.queryForObject("selectRoomDetailByRoomNo", roomNo);
	}
	public void updateRoomInfoBasic(RoomDTO rdto) throws SQLException{
		sqlMap.update("updateRoomInfoBasic", rdto);
	}
	public void updateRoomInfoAdd(RoomDTO rdto) throws SQLException{
		sqlMap.update("updateRoomInfoAdd", rdto);		
	}
}
